/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TickLeaderBar.java
 *
 * Created on Jul 19, 2009, 11:03:23 PM
 */

package com.leadiv.openrule;

import java.awt.Dimension;
import java.awt.Graphics;

/**
 *
 * @author leadiv
 */
public class TickLeaderBar extends javax.swing.JPanel {

    public TickLeaderBar() {
        // so that i can add it to the form.
    }

    /** Creates new form TickLeaderBar */
    public TickLeaderBar(int len) {
        Dimension d = new Dimension();
        this.getSize(d);
        d.height = len;

        this.setSize(d);
        this.setPreferredSize(d);

        this.length = d.height;

        initComponents();
    }

    public TickLeaderBar(int len, boolean isHorizontal) {
        Dimension d = new Dimension();
        this.getSize(d);

        if(isHorizontal) {
            d.height = len;

            this.length = d.height;
        }

        if(!isHorizontal) {
            d.width = len;

            this.length = d.width;
        }

        this.setSize(d);
        this.setPreferredSize(d);
        this.horizontal = isHorizontal;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setLayout(new java.awt.BorderLayout());
    }// </editor-fold>//GEN-END:initComponents

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        if(this.horizontal) {
            g.drawLine(this.pos, 0, this.pos, this.length);
        }
        else {
            g.drawLine(0, this.pos, this.length, this.pos);
        }
    }

    public void setPos(int p) {
        this.pos = p;
        this.validate();
        this.repaint();
    }

    public void setHorizontal(boolean isHorizontal) {
        if(!isHorizontal) {
            Dimension d = new Dimension();
            this.getSize(d);

            d.width = this.length;
            this.setSize(d);
        }

        this.horizontal = isHorizontal;
    }

    public int getPos() {
        return this.pos;
    }

    public boolean getHorizontal() {
        return this.horizontal;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    private int pos = 0;
    private int length = 0;
    private boolean horizontal = true;
}
